package com.gz.droolsrule.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.gz.droolsrule.dao.BaseRuleActionInfoMapper;
import com.gz.droolsrule.pojo.BaseRuleActionInfo;
import com.gz.droolsrule.pojo.BaseRuleSceneInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: RuleActionInfoService <br/>
 * Description: <br/>
 * date: 2019/5/31 16:01<br/>
 *
 * @author gz<br />
 * @since JDK 1.8
 */
@Service
public class RuleActionInfoService {
    @Autowired
    private BaseRuleActionInfoMapper baseRuleActionInfoMapper;

    /**
     * 方法说明: 获取动作列表
     *
     * @param baseRuleActionInfo 参数
     * @param page               分页信息
     */
    public PageInfo<BaseRuleActionInfo> findBaseRuleActionInfoPage(BaseRuleActionInfo baseRuleActionInfo, PageInfo page) {

        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<BaseRuleActionInfo> list = this.baseRuleActionInfoMapper.findBaseRuleActionInfoList(baseRuleActionInfo);
        return new PageInfo<>(list);
    }

    /**
     * 方法说明: 根据场景获取所有的动作信息
     *
     * @param sceneInfo 参数
     */
    public List<BaseRuleActionInfo> findRuleActionListByScene(BaseRuleSceneInfo sceneInfo) {
        if (null == sceneInfo || (null == sceneInfo.getSceneId() &&
                StringUtil.isEmpty(sceneInfo.getSceneIdentify()))) {
            return null;
        }
        return this.baseRuleActionInfoMapper.findRuleActionListByScene(sceneInfo);
    }

    /**
     * 方法说明: 根据规则id获取动作集合
     *
     * @param ruleId 参数
     */
    public List<BaseRuleActionInfo> findRuleActionListByRule(final Long ruleId) {
        if (null == ruleId) {
            return null;
        }
        return this.baseRuleActionInfoMapper.findRuleActionListByRule(ruleId);
    }

    /**
     * 方法说明: 查询是否有实现类的动作
     *
     * @param ruleId 规则id
     */
    public Integer findRuleActionCountByRuleIdAndActionType(Long ruleId) {
        if (null == ruleId) {
            return null;
        }
        return this.baseRuleActionInfoMapper.findRuleActionCountByRuleIdAndActionType(ruleId);
    }
}
